﻿

namespace ShoppingList.ViewModel
{
    
    public class ViewModelLocator
    {
        private static MainViewModel _main;

       
        public ViewModelLocator()
        {
            

            CreateMain();
        }


        #region StatisticsViewModel
        private static StatisticsViewModel _viewModelStatistics;

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        public static StatisticsViewModel ViewModelStatisticsStatic
        {
            get
            {
                if (_viewModelStatistics == null)
                {
                    CreateViewModelStatistics();
                }

                return _viewModelStatistics;
            }
        }

        /// <summary>
        /// Gets the ViewModelPropertyName property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public StatisticsViewModel ViewModelStatistics
        {
            get
            {
                return ViewModelStatisticsStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the ViewModelPropertyName property.
        /// </summary>
        public static void ClearViewModelStatistics()
        {
            if (_viewModelStatistics != null)
            {
                _viewModelStatistics.Cleanup();
                _viewModelStatistics = null;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the ViewModelPropertyName property.
        /// </summary>
        public static void CreateViewModelStatistics()
        {
            if (_viewModelStatistics == null)
            {
                _viewModelStatistics = new StatisticsViewModel();
            }
        }

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void CleanupStatistics()
        {
            ClearViewModelStatistics();
        }
        #endregion

        #region ProductViewModel
        private static ProductsViewModel _viewModelProducs;

        /// <summary>
        /// Gets the ViewModelProducts property.
        /// </summary>
        public static ProductsViewModel ViewModelProductsStatic
        {
            get
            {
                if (_viewModelProducs == null)
                {
                    CreateViewModelProducts();
                }

                return _viewModelProducs;
            }
        }

        /// <summary>
        /// Gets the ViewModelProducts property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public ProductsViewModel ViewModelProducts
        {
            get
            {
                return ViewModelProductsStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the ViewModelProducts property.
        /// </summary>
        public static void ClearViewModelProducts()
        {
            if (_viewModelProducs != null)
            {

          
            _viewModelProducs.Cleanup();
            _viewModelProducs = null;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the ViewModelProducts property.
        /// </summary>
        public static void CreateViewModelProducts()
        {
            if (_viewModelProducs == null)
            {
                _viewModelProducs = new ProductsViewModel();
            }
        }

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
       
        #endregion

        #region ShoppingViewModel
        private static ShoppingViewModel _viewModelShopping;

        /// <summary>
        /// Gets the ViewModelShopping property.
        /// </summary>
        public static ShoppingViewModel ViewModelShoppingStatic
        {
            get
            {
                if (_viewModelShopping == null)
                {
                    CreateViewModelShopping();
                }

                return _viewModelShopping;
            }
        }

        /// <summary>
        /// Gets the ViewModelShopping property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public ShoppingViewModel ViewModelShopping
        {
            get
            {
                return ViewModelShoppingStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the ViewModelShopping property.
        /// </summary>
        public static void ClearViewModelShopping()
        {
            if (_viewModelShopping != null)
            {

          
            _viewModelShopping.Cleanup();
            _viewModelShopping = null;
            }
        }

        /// <summary>
        /// Provides a deterministic way to create the ViewModelShopping property.
        /// </summary>
        public static void CreateViewModelShopping()
        {
            if (_viewModelShopping == null)
            {
                _viewModelShopping = new ShoppingViewModel();
            }
        }

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void Cleanup()
        {
            ClearViewModelShopping();
            CleanupMainViewModel();
            ClearViewModelProducts();
        }
        #endregion

        #region MainViewModel

        public static MainViewModel MainStatic
        {
            get
            {
                if (_main == null)
                {
                    CreateMain();
                }

                return _main;
            }
        }

        /// <summary>
        /// Gets the Main property.
        /// </summary>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public MainViewModel Main
        {
            get
            {
                return MainStatic;
            }
        }

        /// <summary>
        /// Provides a deterministic way to delete the Main property.
        /// </summary>
        public static void ClearMain()
        {
            _main.Cleanup();
            _main = null;
        }

        /// <summary>
        /// Provides a deterministic way to create the Main property.
        /// </summary>
        public static void CreateMain()
        {
            if (_main == null)
            {
                _main = new MainViewModel();
            }
        }

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void CleanupMainViewModel()
        {
            ClearMain();
        }

        #endregion
    }
}